var swiper = new Swiper(".swiper-container",{
	autoplay: 3000,//可选选项，自动滑动
	loop:true
})

var FormatImg = function(selected,container){
	selected.each(function(){
		var imgsrc =  $(this).attr("data-src");
		var wImage = $(this);
		var imgobj = new Image();
		imgobj.onload = function(){
		var h = this.height;
		var w = this.width;
		var winWidth = container.width();
		var winHeight = container.height();
		var rh = winWidth*h/w;
		var rw = winHeight*w/h;
		var paddingLeft = parseInt((winWidth-rw)/2);
		var paddingTop = parseInt((winHeight-rh)/2);
		if(h/w>winHeight/winWidth)	{
			wImage.attr("src",imgsrc).css("height",winHeight).css("padding-left",paddingLeft);
			console.log("1")
		}else{
			wImage.attr("src",imgsrc).css("width","100%").css("padding-top",paddingTop);
			console.log("2")
		}
	}
	imgobj.src = imgsrc;
		
	})
}
FormatImg($(".format"),$(".format").parents(".swiper-container"))


$(function(){
	$(".bottom_block").on("tap",".goToBuy",function(){
		$(".cart-item").before($("<div class='shadow'></div>"))
		var footerH  = $(".myfooter").height();
		$(".cart-item").css("bottom",footerH)
	})
	$(".cart-item").on("tap",".close",function(){
		$(".cart-item").css("bottom","-100%")
		$(".shadow").remove()
	})
})
goToTop($(".goToTop"));

//点击加入购物车
$(".item_add").on("tap",function(){
	var _this = $(this)
	var num = _this.parents(".cart-item").find(".num_txt").val()
	var fcn = $(".footer_cart_num")
	if(fcn.css("display")=="none"){
		fcn.show();
		fcn.text(num);
	}else{
		fcn.text(parseInt(fcn.text())+parseInt(num));
	}
	  fcn.animate({
	  	transform:"scale(1.2)"
	  	},"fast","swing",function(){
	  		fcn.animate({transform:"scale(1)"})
	  	});
})
